package com.zss.admin.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zss.admin.service.AdminUserService;
import com.zss.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("admin/user")
public class AdminUserController {

    @Resource
    AdminUserService userService;

    @RequestMapping("toLogin")
    public String toLogin(){
        return "admin/login";
    }

    @RequestMapping("login")
    @ResponseBody
    public String login(HttpServletRequest request, @RequestBody User user){

        LambdaQueryWrapper<User> querWarpper = new LambdaQueryWrapper<>();
        querWarpper.eq(User::getName,user.getName());
        querWarpper.eq(User::getPassword,user.getPassword());
        User one = userService.getOne(querWarpper);
        if(one==null){
            return "5000";
        }
        request.getSession().setAttribute("adminUserId",one.getId());
        return "2000";
    }

}
